<!-- case syStandardLib -->
<template>
    <div class="caselibrary" v-loading="loading">
        <!-- 表格 -->
        <dy-table :elTable_Options="elTable_Options" @handleClick="handleClick" @bottonHandle="bottonHandle"
            @handleSelect="handleSelect" ref="table" />
    </div>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'
import { Session } from '@/utils/storage'
import { reactive, toRefs, ref, onMounted, nextTick } from 'vue'
import { useCach } from '@/store/cach'

onMounted(() => {
    gettabledata()
})

const router = useRouter()
let pageCach = useCach()

//数据
let state = reactive({
    loading: false
})
let { loading } = toRefs(state)

//实例
let table = ref(null)

//所有展示的数据
let allConfigList = [{
    label: "case编号",
    prop: "case_no",
    columType: 'linkTo',
    width: 180
},
{
    label: "所属科室",
    prop: "sy_owndeptid",
    columType: 'arrayKey',
    width: 180,
    keyName: 'department_name',
},
{
    label: "标准试验任务",
    prop: "standardtask",
    columType: 'text',
    width: 140
},
{
    label: "试验名称",
    prop: "test_name",
    columType: 'text',
    width: 120
},
{
    label: "执行标准",
    prop: "execute_standard",
    columType: 'text',
    width: 120
},
{
    label: "执行岗位",
    prop: "work_hour_position",
    columType: 'select',
    commonVarrName: 'case_work_hour',
    width: 120
},
{
    label: "试验类别",
    prop: "test_type",
    columType: 'select',
    commonVarrName: 'case_test_type',
    width: 120
},
{
    label: "参考价格标准",
    prop: "reference_price",
    columType: 'text',
    width: 130
}, {
    label: "试验对象",
    prop: "test_object",
    columType: 'text',
},
{
    label: "负责科室",
    prop: "response_depart",
    columType: 'arrayKey',
    width: 140,
    keyName: "department_name"
}]

//表格数据
let elTable_Options = reactive({
    pagename: '台架试验CASE库', //页面名称
    selection: false, //true 单选
    allConfigList: allConfigList, //需要配置项就加 不需要可以不写
    eltableArr: allConfigList, //表头数据
    table_type: "standardcase_试验CASE库", //列表配置喜好 和 allConfigList一起
    getwayname: 'standardcase', //接口名
    uid: 'standardcase_table',
    // ifturnpage: 是否展示分页 
    //按钮
    opbutton: [{
        label: '新增case',
        dealway: 'createdata',
        icon: 'Plus',
        type: "primary",
        keyV: "add",
        disabled: false
    }, {
        label: "批量导入",
        dealway: "importData",
        icon: 'Download',
        type: "",
        keyV: "import",
        disabled: false
    }, {
        label: "批量导出",
        dealway: "exportData",
        icon: 'Upload',
        type: "",
        keyV: "export",
        disabled: false
    }],
    //查询栏
    searchList: [{
        label: "搜索case编号、试验名称、标准试验任务",
        key: "search",
        searchtype: 'input',
        width: 330
    },
    {
        label: "所属科室",
        key: "sy_owndeptid", //级联选择器
        searchtype: 'Cascader',
        width: 240,
        options: [],
        props: {
            checkStrictly: true,
            value: "id",
            label: "department_name",
        }
    },
    {
        label: "执行岗位",
        key: "work_hour_position",
        searchtype: 'select',
        options: []
    }],
    /* tab表格菜单 */
    menuname: 'myoffice',
    elMenuArr: [{
        key: 'all',
        value: '全部',
    }, {
        key: 'myoffice',
        value: '我科室的',
        addConditions: [{
            key: "select_type",
            value: "myoffice"
        }, {
            key: "user_id",
            value: Session.get('UserMsg').id
        }]
    }, {
        key: 'myApproval',
        value: '待我审批',
        addConditions: [
            {
                key: "select_type",
                value: "myapproval"
            }, {
                key: "user_id",
                value: Session.get('UserMsg').id
            }
        ]
    }],
    /* 导出导出参数配置 */
    importexport: {
        //导入参数
        import_templatename: 'Case',
        import_filename: '试验CASE库模板.xls',
        import_api: 'importstandardcase',
        // 导出参数
        export_filename: '试验CASE库列表.xls',
        export_api: 'exportstandardcase'
    }
})

//获取数据
let gettabledata = () => {
    if (pageCach.tableInfo && pageCach.tableInfo.uid == elTable_Options.uid) {
        elTable_Options.menuname = pageCach.tableInfo.tabName
        table.value.setSearchData(pageCach.tableInfo.searchParams)
        nextTick(() => {
            table.value.getTableData(pageCach.tableInfo)
        })
        return
    }
    nextTick(() => {
        table.value.getTableData()
    })
}

//链接点击
let handleClick = (row, index) => {
    //查看
    if (index == 3) {
        //记录当前页面信息
        pageCach.changeTableInfo({
            //页签
            tabName: elTable_Options.menuname,
            //p
            p: table.value.tableIntance.state.p,
            //pageSize
            size: table.value.tableIntance.state.size,
            //搜索参数
            searchParams: table.value.searchParams,
            //唯一标识
            uid: elTable_Options.uid
        })

        router.push({
            path: `/syStandardLib/caselibrary/view/${row.id}`
        })
    }
}

//按钮点击
let bottonHandle = (wayname) => {
    if (wayname == 'createdata') {
        //新增
        router.push({
            path: '/syStandardLib/caselibrary/create'
        })
        return
    }

    if (wayname == '') { }
}

//切换tab
let handleSelect = (key) => {
    elTable_Options.menuname = key
    nextTick(() => {
        table.value.conditional()
    })
}

</script>

<style lang="scss" scoped></style>